package com.lemon.cloud.gray.util;

import cn.hutool.core.util.StrUtil;
import com.lemon.cloud.comm.constants.GrayConstant;
import com.lemon.cloud.gray.support.GrayFlagContextHolder;
import lombok.experimental.UtilityClass;

@UtilityClass
public class GrayUtil {

    public String getGrayFlag(){
        //获取环境变量
        String flag = GrayConstant.STR_BOOLEAN_FALSE;
        if (StrUtil.isNotEmpty(System.getProperty(GrayConstant.GRAY_FLAG))){
            flag =  System.getProperty(GrayConstant.GRAY_FLAG);
        }
        if (StrUtil.isNotEmpty(GrayFlagContextHolder.getGrayFlag())){
            flag =  GrayFlagContextHolder.getGrayFlag();
        }
        if (!GrayConstant.STR_BOOLEAN_TRUE.equals(flag)){
            flag = GrayConstant.STR_BOOLEAN_FALSE;
        }
        return flag;
    }

    public boolean isGray(){
        return GrayConstant.STR_BOOLEAN_TRUE.equals(getGrayFlag());
    }
}
